//
//  HomePageUserLikeListCell.m
//  ShowYork
//
//  Created by hxh on 2020/12/21.
//  Copyright © 2020 hxh. All rights reserved.
//

#import "HomePageUserLikeListCell.h"
#import "HomePageContentModel.h"
@interface HomePageUserLikeListCell ()
@property (nonatomic,strong)UIImageView *contentImgView;
@property (nonatomic,strong)UIImageView *typeImgView;
@property (nonatomic,strong)UILabel *contentLb;
@property (nonatomic,strong)UIImageView *labelImgView;
@end

@implementation HomePageUserLikeListCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUI];
    }
    return self;
}

- (void)setUI{
    
    self.backgroundColor = [UIColor whiteColor];
    
    self.contentImgView = [[UIImageView alloc]init];
    self.contentImgView.contentMode = UIViewContentModeScaleAspectFill;
    self.contentImgView.layer.masksToBounds = YES;
    self.contentImgView.backgroundColor = RGBA(240, 240, 240, 1);
    [self.contentView addSubview:self.contentImgView];
    
    
    self.labelImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"homePage_tag_context_bg"]];
    [self.contentView addSubview:self.labelImgView];
    
    self.contentLb = [[UILabel alloc]init];
    self.contentLb.textColor = RGBA(58, 58, 58, 1);
    self.contentLb.font = font(12);
    self.contentLb.numberOfLines = 0;
    self.contentLb.textAlignment = NSTextAlignmentCenter;
 
    [self.contentView addSubview:self.contentLb];
    
    self.typeImgView = [[UIImageView alloc]init];
    [self.contentView addSubview:self.typeImgView];
    
    
    
    [self.contentImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self.contentView);
    }];
    
    [self.labelImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self.contentView);
    }];
    
    [self.contentLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(16);
        make.bottom.equalTo(self.typeImgView.mas_top).offset(-16);
        make.left.equalTo(self.contentView).offset(3);
        make.right.equalTo(self.contentView).offset(-3);
    }];
    [self.typeImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView).offset(-8);
        make.left.equalTo(self.contentView).offset(8);
        make.size.mas_equalTo(CGSizeMake(16, 16));
    }];
}

- (void)setModel:(HomePageItemModel *)model{
    _model = model;
    // 文字情况
    if (model.contentType.intValue == 1) {
        self.contentImgView.hidden = YES;
        self.labelImgView.hidden = NO;
        self.typeImgView.image = [UIImage imageNamed:@"home_like_content_tag"];
        self.contentLb.text = model.contentText;
    }else{
        self.labelImgView.hidden = YES;
        self.contentImgView.hidden = NO;
        self.contentLb.text = @"";
        // 判断图片还是视频
        if (model.contentType.intValue == 2) {
            self.typeImgView.image = [UIImage imageNamed:@"home_like_image_tag"];
            [self.contentImgView sd_setImageWithURL:[NSURL URLWithString:model.urls.firstObject] completed:nil];
        }else{
            self.typeImgView.image = [UIImage imageNamed:@"home_like_video_tag"];
            __block HomePageContentModel *item = nil;
            [model.contents enumerateObjectsUsingBlock:^(HomePageContentModel *_Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                // 图片
                if (obj.seq.intValue == 1) {
                    item = obj;
                    *stop = YES;
                }
            }];
            
            [self.contentImgView sd_setImageWithURL:[NSURL URLWithString:item.postUrl] completed:nil];
            
        }
        
    }
}

@end
